<html>
<head><meta charset="utf-8"><title>MCP: More Cranelift-friendly portable SIM… compiler-team#381 · t-compiler/major changes · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/index.html">t-compiler/major changes</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html">MCP: More Cranelift-friendly portable SIM… compiler-team#381</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="215569238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215569238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215569238">(Nov 04 2020 at 11:36)</a>:</h4>
<p>A new proposal has been announced: <a href="https://github.com/rust-lang/compiler-team/issues/381">MCP: More Cranelift-friendly portable SIMD intrinsics #381</a>. It will be announced at the next meeting to try and draw attention to it, but usually MCPs are not discussed during triage meetings. If you think this would benefit from discussion amongst the team, consider proposing a design meeting.</p>



<a name="215575116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215575116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215575116">(Nov 04 2020 at 12:47)</a>:</h4>
<p>Seems like these should go in compiler_builtins, not miri/the const eval engine, otherwise you can only execute them at compile time.</p>



<a name="215575252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215575252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215575252">(Nov 04 2020 at 12:48)</a>:</h4>
<p>But then any backend needs support for SIMD as part of the calling convention, and any use of an intrinsic incurs a function call.</p>



<a name="215582350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215582350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215582350">(Nov 04 2020 at 13:51)</a>:</h4>
<p>You can have the compiler_builtins implementation as fallback for when there is no native implementation for a platform-intrinsic. SIMD supports as part of the calling convention is not necessary. You can just pass the arguments using the regular struct calling convention. A disadvantage of having it in compiler_builtins is that platform-intrinsics work for any combination of lane type and vector size, while regular functions can't.</p>



<a name="215583749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215583749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215583749">(Nov 04 2020 at 14:02)</a>:</h4>
<p>So in reference to this part of the MCP:</p>
<blockquote>
<p>We want to write reference implementations in plain Rust rather than in MIR, but also want backends to be able to use them to emit code. Is this something that's possible in the compiler? Is compiler-builtins the right place for them?</p>
</blockquote>
<p>This is probably the same as what <span class="user-mention" data-user-id="133247">@bjorn3</span> said, but what I would imagine is that we would write "plain Rust" functions but give them some kind of special attribute</p>



<a name="215584125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215584125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215584125">(Nov 04 2020 at 14:04)</a>:</h4>
<p>such that if there is a <em>direct call</em> to the function (in a backend that can handle it) we generate special SIMD code</p>



<a name="215584139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215584139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215584139">(Nov 04 2020 at 14:04)</a>:</h4>
<p>but otherwise we can treat it like a normal function call</p>



<a name="215584157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215584157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215584157">(Nov 04 2020 at 14:05)</a>:</h4>
<p>I think this is how we handle intrinsics anyway?</p>



<a name="215584186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215584186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215584186">(Nov 04 2020 at 14:05)</a>:</h4>
<p>I know that <span class="user-mention" data-user-id="119009">@eddyb</span> had proposed this model in particular to handle things like indirect function calls</p>



<a name="215584199"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215584199" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215584199">(Nov 04 2020 at 14:05)</a>:</h4>
<p>though I think in that original proposal you'd see something</p>



<a name="215584215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215584215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215584215">(Nov 04 2020 at 14:05)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">some_intrinsic</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">some_intrinsic</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="215584252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215584252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215584252">(Nov 04 2020 at 14:05)</a>:</h4>
<p>the idea being that an indirect call invokes the <code>some_intrinsic</code> function and the function body itself contains a <em>direct call</em>, which gets generated with the special behavior</p>



<a name="215584356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215584356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215584356">(Nov 04 2020 at 14:06)</a>:</h4>
<p>That is basically what <code>drop_in_place</code> does I think.</p>



<a name="215584641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215584641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215584641">(Nov 04 2020 at 14:08)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="k">fn</span> <span class="nf">drop_in_place</span><span class="o">&lt;</span><span class="n">T</span>: <span class="o">?</span><span class="nb">Sized</span><span class="o">&gt;</span><span class="p">(</span><span class="n">to_drop</span>: <span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="n">T</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">// Code here does not matter - this is replaced by the</span>
<span class="w">    </span><span class="c1">// real drop glue by the compiler.</span>

<span class="w">    </span><span class="c1">// SAFETY: see comment above</span>
<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">drop_in_place</span><span class="p">(</span><span class="n">to_drop</span><span class="p">)</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="215584646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215584646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215584646">(Nov 04 2020 at 14:08)</a>:</h4>
<p>sounds right</p>



<a name="215584676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215584676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215584676">(Nov 04 2020 at 14:08)</a>:</h4>
<p>anyway, I think this would work, right? the idea being that we give the "reference impl" semantics as plain rust</p>



<a name="215584898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215584898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215584898">(Nov 04 2020 at 14:10)</a>:</h4>
<p>How would the "reference impl" be written for say <code>simd_add</code> though? The full signature is <code>extern "platform-intrinsic { fn simd_add&lt;T&gt;(a: T, b: T) -&gt; T; }</code>. This accepts vector types with any lane size and lane count.</p>



<a name="215586456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215586456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215586456">(Nov 04 2020 at 14:20)</a>:</h4>
<p>Well, the final version would probably need some trait bounds, or just compile error if unacceptable types are put in.</p>
<p>However, being allowed to use types without direct hardware support is <em>by design</em>, so that much at least has to be allowed.</p>



<a name="215586611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215586611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215586611">(Nov 04 2020 at 14:21)</a>:</h4>
<p>I am not talking about the interface. I am talking about the implementation. What would you write in the function body?</p>



<a name="215616856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215616856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215616856">(Nov 04 2020 at 17:45)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> yeah that wouldn't work :)  I agree it would need some kind of trait bounds to make it writeable</p>



<a name="215617040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215617040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215617040">(Nov 04 2020 at 17:47)</a>:</h4>
<p>Currently all intrinsics in compiler_builtins are non-generic. I don't know if it is possible to introduce generics given that the public interface is through unmangled symbols and there is a lot of special casing of compiler_builtins in rustc.</p>



<a name="215651099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215651099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215651099">(Nov 04 2020 at 22:49)</a>:</h4>
<p>Hmm, I guess it could be done like doc items or something -- write everything as all normal rust functions but with a special attribute on them so the backend can swap them out for whatever the IR has if they have support for the operation.</p>



<a name="215653899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215653899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215653899">(Nov 04 2020 at 23:23)</a>:</h4>
<p>It sounds like our first job is to figure out how to write these reference implementations and we’re generally ok with using <code>extern “platform-intrinsic”</code>?</p>



<a name="215669460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215669460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215669460">(Nov 05 2020 at 04:06)</a>:</h4>
<p>The reason I was pushing for plain Rust reference implementations that we can directly call was that I was expecting an API that hands backends MIR would obscure the contract of these portable methods and make them harder to work on. But if coming up with a few macros to make “I have a <code>simd_add</code>, what code should I emit?” easier to understand for us non-compiler folk has fewer unknowns than trying to come up with a pure Rust approach then maybe we should try go that way</p>



<a name="215723394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215723394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215723394">(Nov 05 2020 at 15:02)</a>:</h4>
<p>I have to bring some of those back into cache obviously but</p>



<a name="215723498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215723498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215723498">(Nov 05 2020 at 15:03)</a>:</h4>
<p>I remember that way back in Ye Olde Days huonw had these special intrinsics that kind of hard-coded simd over some set of types but that set was ad-hoc and not defined via traits</p>



<a name="215723508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215723508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215723508">(Nov 05 2020 at 15:03)</a>:</h4>
<p>(probably this is still true?)</p>



<a name="215723571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215723571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215723571">(Nov 05 2020 at 15:04)</a>:</h4>
<p>I guess I didn't get a clear picture from the MCP what kind of data types these intrinsics need to operate over</p>



<a name="215723641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215723641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215723641">(Nov 05 2020 at 15:04)</a>:</h4>
<p>I think it'd be nice if we can write "plain old Rust" and not hard-coded MIR etc</p>



<a name="215723692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215723692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215723692">(Nov 05 2020 at 15:04)</a>:</h4>
<p>The data types they work on are all <code>#[repr(simd)]</code> types with the correct lane types.</p>



<a name="215726078"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215726078" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215726078">(Nov 05 2020 at 15:21)</a>:</h4>
<p>yes ok this is roughly what I remember</p>



<a name="215759771"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215759771" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215759771">(Nov 05 2020 at 19:09)</a>:</h4>
<p>So specifically the types would be signed and unsigned integer types (all widths) and float types (all widths) for 128-bit simd initially, but also 64, 256, 512 eventually, and in the far future doubtlessly more. These would need to be supported <em>even if</em> they're not hardware supported, so on some targets a particular op might need a fallback even if most ops for that type don't.</p>



<a name="215759893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215759893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215759893">(Nov 05 2020 at 19:10)</a>:</h4>
<p>when i say "integer" i include usize/isize but i do not include char or bool.</p>



<a name="215760012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215760012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215760012">(Nov 05 2020 at 19:11)</a>:</h4>
<p>and the operations available for floats would be not be the exact same operations as for integers (eg: float has sqrt, integer does not)</p>



<a name="215928989"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215928989" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215928989">(Nov 07 2020 at 03:23)</a>:</h4>
<p>Ok, so what if we wrote our fallback implementations in pure Rust in terms of <code>[T; N]</code>, and then manually monomorphized a bunch of them as <code>compiler_builtins</code> using a naming convention we can easily generate from the inputs, like LLVM’s intrinsics. Kind of <a href="https://play.integer32.com/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=2a75bda1e28f70ee08c0ec3612ba2388">like this</a>.</p>



<a name="215929050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215929050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215929050">(Nov 07 2020 at 03:25)</a>:</h4>
<p>We could easily use macros to generate <code>simd_add_i32x4</code>-style functions from our single generic <code>simd_add</code></p>



<a name="215936735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215936735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215936735">(Nov 07 2020 at 05:41)</a>:</h4>
<p>Or we could <a href="https://play.integer32.com/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=6925edb0799459177ccafcc4e3814c27">use some traits</a> to specialize behavior, while still generating the same monomorphized intrinsics</p>



<a name="215990942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/215990942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#215990942">(Nov 08 2020 at 05:51)</a>:</h4>
<p>I’ve updated the MCP text to include some more details on how these fallbacks could be written.</p>



<a name="216774924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/216774924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#216774924">(Nov 15 2020 at 06:53)</a>:</h4>
<p>I've updated this MCP again. It's now got a conceptual, but working, example of how this could all hang together: <a href="https://github.com/rust-lang/compiler-team/issues/381">https://github.com/rust-lang/compiler-team/issues/381</a></p>
<p>It would be great to get some more <span aria-label="eyes" class="emoji emoji-1f440" role="img" title="eyes">:eyes:</span> on it!</p>



<a name="216779708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/216779708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#216779708">(Nov 15 2020 at 08:47)</a>:</h4>
<p>I assume the <code>codegen_support</code> and <code>codegen_cranelift</code> modules are what the compiler would do and not included directly in <code>compiler_builtins</code>, right?</p>



<a name="216781058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/216781058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#216781058">(Nov 15 2020 at 09:17)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> I think so, yeh. The idea being Cranelift only has to come up with an implementation of that <code>codegen_cranelift::simd_fallback</code> that can pack and unpack <code>#[repr(simd)]</code> types as slices so they can be passed to the builtin it names by convention</p>



<a name="216781103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/216781103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ashley Mannix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#216781103">(Nov 15 2020 at 09:18)</a>:</h4>
<p>So I think the difference between this and the API you were originally talking about is instead of being handed some MIR you get handed a function to call</p>



<a name="232768289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/232768289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#232768289">(Apr 01 2021 at 14:43)</a>:</h4>
<p><span class="user-group-mention" data-user-group-id="492">@T-compiler</span>: Proposal <a href="https://github.com/rust-lang/compiler-team/issues/381#issuecomment-811957026">#381</a> has been seconded, and will be approved in 10 days if no objections are raised.</p>



<a name="235534665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/235534665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#235534665">(Apr 21 2021 at 15:48)</a>:</h4>
<p><span class="user-mention" data-user-id="204346">@Ashley Mannix</span> Thank you so much.</p>



<a name="237694962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/MCP%3A%20More%20Cranelift-friendly%20portable%20SIM%E2%80%A6%20compiler-team%23381/near/237694962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/MCP.3A.20More.20Cranelift-friendly.20portable.20SIM.E2.80.A6.20compiler-team.23381.html#237694962">(May 06 2021 at 17:10)</a>:</h4>
<p>This proposal has been accepted: <a href="https://github.com/rust-lang/compiler-team/issues/381">#381</a>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>